package ex.klmy.gov.module;

import ex.klmy.gov.bean.Category;
import ex.klmy.gov.utils.Sql;
import org.nutz.dao.Cnd;
import org.nutz.ioc.annotation.InjectName;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import java.util.List;

/**
 * Created by xiaguoqiang on 16/11/3.
 */
@IocBean
@InjectName
@At("/lmfl")
public class CategoryAction extends BaseAction{

    @At
    @Ok("jsonp")
    public Object getInteractionCategory() {
        List<Category> l = basicDao.search(Category.class, Cnd.wrap("where wbtreeid = '9176' or   wbtreeid = '1042' and wbname = '热点问答'  or wbtreeid = '9183'"));
        return l;
    }

    @At
    @Ok("jsonp")
    public Object getMainServiceCategory() {
        List<Category> l = basicDao.search(Category.class, Cnd.wrap("where wbtreefid = 1024 and wbapptype = 'news' and wbshowstatus = 1"));
        return l;
    }

    @At
    @Ok("jsonp")
    public Object getCategoryByPid(@Param("pId") String pid) {
        String sql = "select ((select COUNT(*) from wbtree where wbtreefid = A.wbtreeid)) as childCount,* from wbtree A where " +
                "owner = 831749743 and " +
                "a.wbtreefid = " + pid;
        List<Category> l =  basicDao.searchMAll(Category.class,sql);
//        List<Category> l = basicDao.search(Category.class,Cnd.where("wbtreefid","=",pid).and("owner","=","831749743"));
        return l;
    }

    @At
    @Ok("jsonp")
    public Object getCategoryWithImgByPid(@Param("pId") String pid) {
        String sql = "SELECT wbtree.wbtreeid, wbtree.wbname, wbtree.wbename, wbimage.wbpicurl FROM wbtree LEFT JOIN wbimage ON wbimage.wblinkurl LIKE '%' + CAST(wbtree.wbtreeid AS VARCHAR(10)) + '%' WHERE wbtree.wbtreefid = "+ pid +" AND wbimage.wbtreeid = " + pid;
        List<Category> l = basicDao.searchMAll(Category.class,sql);
        return l;
    }
}
